﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using FMSpaceShooter.Screens;
using FMSpaceShooter.ScreenManager;

namespace FMSpaceShooter.GameObjects
{
    class SplitterBullet : BulletBase
    {
        public new const string TypeName = "SplitterBullet";
        public new const bool IsStandardBullet = true;

        public const string imageName = "Images/Bullets/SplitterBullet";
        public const int rof = 170;
        public override int Damage { get { return 80; } }
        public override int RateOfFire { get { return rof; } }
        public const int MaxVelocity = 1000;
        private static int bulletLevel = 0;
        public static int BulletLevel { get { return bulletLevel; } }

        

        public SplitterBullet(GameplayScreen screen, Vector2 initial, float rotation)
            : base(screen, imageName)
        {
            this.position = initial;
            this.rotation = rotation;

        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            position += (float)(MaxVelocity * gameTime.ElapsedGameTime.TotalSeconds) * Util.Tools.AngleToVector(rotation);
            for (int i = -1+(bulletLevel*-1); i <= 1+bulletLevel; i++)
            {
                screen.GOM.AddToPlay(new BulletFragment(screen, position, rotation + (float)Math.PI*i / 48));
            }
            this.Die();
                          
        }


        public static void increaseLevel()
        {
            if (bulletLevel < 10)
            {
                bulletLevel++;
            }
        }

        public static void resetLevel()
        {
            bulletLevel = 0;
        }

    }




    class BulletFragment : BulletBase
    {
        public const string imageName = "Images/Bullets/SplitterBullet";
        public const int rof = 150;
        public override int Damage { get { return 30; } }
        public override int RateOfFire { get { return rof; } }
        public const int MaxVelocity = 1000;


        public BulletFragment(GameplayScreen screen, Vector2 initial, float rotation)
            : base(screen, imageName)
        {
            this.position = initial;
            this.rotation = rotation;
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            position += (float)(MaxVelocity * gameTime.ElapsedGameTime.TotalSeconds) * Util.Tools.AngleToVector(rotation);
        }

    }
}
